﻿
@{
    ViewData["Title"] = "通知列表";
}
<blockquote class="layui-elem-quote quoteBox">
    <div class="layui-inline">
        <div class="layui-input-inline">
            <input type="text" name="Description" data-op="cn" class="layui-input searchVal" placeholder="请输入关键词" />
        </div>
        <a class="layui-btn search_btn" data-type="reload">搜索</a>
    </div>
    <div></div>
</blockquote>

<table id="laytable" lay-filter="noticeList"></table>
@section script{
    <script type="text/javascript">
        layui.use(['tools', 'laytpl'], function () {
            var $ = layui.$, table = layui.table, tools = layui.tools, form = layui.form, total = 0;

            table.render({
                elem: '#laytable',
                url: '/BlogManage/Notice/Index',
                method: 'post',
                toolbar: '#toolsHead',
                loading: true,
                height: "full-125",
                limit: 15,
                limits: [10, 15, 20, 25, 30, 35, 40, 45, 50],
                page: true,
                where: { order: 'SortCode asc' },
                cols: [[
                    { type: 'numbers' },
                    { field: 'Description', title: '通知内容' },
                    {
                        field: 'Link', title: '链接'
                    },
                    { field: 'SortCode', title: '排序', sort: true },
                    { field: 'CreatorTime', title: '创建日期', sort: true },
                    { title: '操作', fixed: 'right', align: 'center', hide: rowButton.length == 0, width: rowButton.length * 80, templet: '#toolsRow' }
                ]],
                done: function (res, curr, count) {
                    total = count;
                }
            });

            table.on('tool(noticeList)', function (obj) {
                var url = $(this).data("url"), layEvent = obj.event;
                active[layEvent](url, obj.data.Id);
            });

            table.on('toolbar(noticeList)', function (obj) {
                var url = $(this).data("url");
                var layEvent = obj.event;
                active[layEvent](url);
            });

            table.on('sort(noticeList)', function (obj) {
                table.reload("laytable", {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: {
                        //排序字段
                        order: obj.field + " " + obj.type //排序方式

                    }
                })
            });

            $(".search_btn").click(function () {
                table.reload("laytable", {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: tools.condition()
                });
            });

            var active = {
                add: function (url) {
                    tools.moduleOpen({
                        title: "新增通知信息",
                        url: url + "?total=" + total,
                        width: "480px",
                        height: "420px",
                        callBack: function (index, layero) {
                            var iframeWindow = window["layui-layer-iframe" + index];
                            iframeWindow.layui.form.on("submit(save)", function (data) {
                                data.field.EnabledMark = data.field.EnabledMark == 1;
                                tools.submit({
                                    url: url,
                                    data: data.field,
                                    loading: "正在保存数据...",
                                    success: function () {
                                        table.reload("laytable");//重新加载
                                        layer.close(index);
                                    }
                                });
                            });
                            layero.find("iframe").contents().find("#btnSave").trigger("click");
                        }
                    });
                },
                edit: function (url, id) {
                    tools.moduleOpen({
                        title: "编辑通知信息",
                        url: url + "?key=" + id,
                        width: "480px",
                        height: "420px",
                        callBack: function (index, layero) {
                            var iframeWindow = window["layui-layer-iframe" + index];
                            iframeWindow.layui.form.on("submit(save)", function (data) {
                                data.field.EnabledMark = data.field.EnabledMark == 1;
                                tools.submit({
                                    url: url + "?Id=" + id,
                                    data: data.field,
                                    loading: "正在保存数据...",
                                    success: function () {
                                        table.reload("laytable");//重新加载
                                        layer.close(index);
                                    }
                                });
                            });
                            layero.find("iframe").contents().find("#btnSave").trigger("click");
                        }
                    });
                },
                delete: function (url, id) {
                    tools.submitConfrim({
                        prompt: "您确定需要删除当前通知信息吗？",
                        url: url,
                        data: { key: id },
                        success: function () {
                            table.reload("laytable");//重新加载
                        }
                    });
                }
            };
        });
    </script>
}
